home *** CD-ROM | disk | FTP | other *** search
- Path: news.netam.net!alpha!bgc
- From: bgc@alpha.netam.net (The Bowling Green Connection)
- Newsgroups: comp.lang.c
- Subject: Re: HELP! Modifying the EOF in a file!
- Date: 13 Mar 1996 20:05:01 GMT
- Organization: NetAmerica, Bowling Green, KY.
- Distribution: world
- Message-ID: <4i79pd$slk@news.netam.net>
- References: <4i585k$4ia@news.netam.net> <4i5pb4$fae@sparcserver.lrz-muenchen.de>
- NNTP-Posting-Host: alpha.netam.net
- X-Newsreader: TIN [version 1.2 PL2]
-
- ua302aa@lrz-muenchen.de wrote:
- : I fail to see where you want to _write_ to "file.txt"
-
- The whole situation is rather involved, so I stuck to
- simplicity.. but if you want to know the whole
- situation, here it is:
-
- I have a queue set up on the internet to mail mime-format
- messages to myself (there is a reason why, but it's
- too long for me to explain now). Basically, from a
- browser you can click a submit button which will call
- this SendMail procedure. The procedure extracts information
- from the fillout form on the page and creates a text file
- under the name of mime.body in Unix.
-
- Now, since it is possible for two or more people to submit
- messages at the same time, I have to make sure that the
- mime.body file is locked (I use the flock() procedure)
- while data is being written to it, and while it is being
- mailed with the mailto command (which can send mime-
- formatted messages). So everyone else must wait until
- the file becomes unlocked before their message gets
- queued up for mailing.
-
- The way I send the message in mime format is by making
- a system call that runs an environment command and
- runs the mailto command, which has piped to it the
- contents of a file called mime.wrap, which references
- the mime.body (with mailto's special formatting
- language) file. SO... If I want to send a mime message,
- I first have to have the mime.body file in place and
- ready to go. I can't just fopen("newfile", "w").
- I have to modify the old file and possibly have to
- shorten it. The ftruncate() procedure will work
- for me here, and I thank all of you for pointing me
- in the right direction!
-
- The only thing that still bothers me is my method for
- locking the file. I have to figure out a way to keep
- other processes from editing the mime.body file UNTIL
- the mailto command gets finished mailing the thing
- off!
-
- Can I keep the file open (and locked), call a fflush(),
- and send the mail before closing it? This is one
- way I could maintain the lock on the file, because I
- understand that if I close the file, the lock is
- removed.
-
- Eddie,
- bgc@bgcky.com
-